package com.engine.cese.duss.srm.workflow_srm.web;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.cese.duss.srm.util.CalUtil;
import com.engine.cese.duss.srm.util.GenUtil;
import com.weaver.general.BaseBean;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Title: Ecology9
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2021-03-30
 * @Description: 招采过程
 * @ModifyLog:
 **/

public class WeaWorkflowAction {
    /**
     * @Description: 获取招标采购立项流程状态
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getCglxWfStatus")
    @Produces({MediaType.TEXT_PLAIN})
    public String getCglxWfStatus(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            RecordSet rs = new RecordSet();
            String sql = "select currentnodetype from workflow_requestbase where requestid=?";
            rs.executeQuery( sql, cglxd );
            rs.next();
            String currentnodetype = Util.null2String( rs.getString( "currentnodetype" ) );
            apidatas.put( "currentnodetype", currentnodetype );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单获取流程状态
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getCglxd2Status")
    @Produces({MediaType.TEXT_PLAIN})
    public String getCglxd2Status(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            String lc = Util.null2String( request.getParameter( "lc" ) );
            String table = Util.null2String( request.getParameter( "table" ) );
            JSONObject jsonData = new JSONObject();
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String formTable = baseBean.getPropValue( "SrmWfTab", table );
            String sqlwhere = "1=1";
            //单据编号
            if (!"".equals( cglxd )) {
                sqlwhere += " and t1.cglxd = '" + cglxd + "' ";
            }
            if (!"".equals( lc )) {
                sqlwhere += " and t1.lc = '" + lc + "' ";
            }
            String sql = "select t1.requestid,t2.currentnodetype from " + formTable
                    + " t1 left join workflow_requestbase t2 on t1.requestid=t2.requestid where " + sqlwhere;
            rs.executeQuery( sql );
            rs.next();
            String requestid = Util.null2String( rs.getString( "requestid" ) );
            String currentnodetype = Util.null2String( rs.getString( "currentnodetype" ) );
            jsonData.put( "requestid", requestid );
            jsonData.put( "currentnodetype", currentnodetype );
            apidatas.put( "datas", jsonData );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据轮次、采购立项单获取发起评标的评标规则
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getPfgzData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getPfgzData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            List<Map<String, String>> dataList1 = new ArrayList<>();
            List<Map<String, String>> dataList2 = new ArrayList<>();
            List<Map<String, String>> dataList3 = new ArrayList<>();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            String lc = Util.null2String( request.getParameter( "lc" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String fqpb = baseBean.getPropValue( "SrmWfTab", "fqpb" );
            String kbjghq = baseBean.getPropValue( "SrmWfTab", "kbjghq" );
            String dfb = baseBean.getPropValue( "SrmWfTab", "dfb" );
            String gystb = baseBean.getPropValue( "SrmWfTab", "gystb" );
            String sql = "select zhpbswgz,jsfjsgz,swbl,jsbl,jgjsbl,jzj,swfjsgz,zpl1kf,fpl1kf " +
                    "from " + fqpb + "  where lc=? and cglxd=?";
            rs.executeQuery( sql, lc, cglxd );
            rs.next();
            String zhpbswgz = Util.null2String( rs.getString( "zhpbswgz" ) );//综合评标商务规则
            String swbl = Util.null2String( rs.getString( "swbl" ) );//商务比例(%)
            swbl = "".equals( swbl ) ? "0" : CalUtil.fDivide( swbl, "100", 4 );
            String jsbl = Util.null2String( rs.getString( "jsbl" ) );//技术比例(%)
            jsbl = "".equals( jsbl ) ? "0" : CalUtil.fDivide( jsbl, "100", 4 );
            String jgjsbl = Util.null2String( rs.getString( "jgjsbl" ) );//价格基数比例%
            jgjsbl = "".equals( jgjsbl ) ? "0" : CalUtil.fDivide( jgjsbl, "100", 4 );
            String jzj = Util.null2String( rs.getString( "jzj" ) );//基准价
            String swfjsgz = Util.null2String( rs.getString( "swfjsgz" ) );//商务分计算规则
            String jsfjsgz = Util.null2String( rs.getString( "jsfjsgz" ) );//技术分计算规则
            String zpl1kf = Util.null2String( rs.getString( "zpl1kf" ) );//正偏离1%扣分
            String fpl1kf = Util.null2String( rs.getString( "fpl1kf" ) );//负偏离1%扣分
            String sql1 = "select t1.gys,t1.wsbj,t1.wsbj1 as pbbj,t1.zfxs,t1.fkxs,t1.sl \n" +
                    "from " + kbjghq + " t left join " + kbjghq + "_dt1 t1 \n" +
                    "on t.id=t1.mainid where t.lc=? and t.cglxd=? and t1.sfyxtb=0";
            rs.executeQuery( sql1, lc, cglxd );
            while (rs.next()) {
                Map<String, String> resultMap = new HashMap<>();
                String gysmc = Util.null2String( rs.getString( "gys" ) );//供应商名称
                String gysmcname = GenUtil.getId2Gysmc( gysmc );
                String wsbj = Util.null2String( rs.getString( "wsbj" ) );//投标报价
                String slId = Util.null2String( rs.getString( "sl" ) );//税率
                String sl = GenUtil.getId2Sl( slId );
                String pbbj = Util.null2String( rs.getString( "pbbj" ) );//评标报价
                String zfxs = Util.null2String( rs.getString( "zfxs" ) );//支付系数
                String fkxs = Util.null2String( rs.getString( "fkxs" ) );//付款系数
                /* 商务分计算规则*/
                String swdf = "";//商务得分
                if ("0".equals( zhpbswgz )) {//平均价
                    String pjj = "";
                    if ("0".equals( swfjsgz )) {//扣除最高最低
                        pjj = GenUtil.getPjj( lc, cglxd, swfjsgz, kbjghq );
                    } else if ("1".equals( swfjsgz )) {//不扣除
                        pjj = GenUtil.getPjj( lc, cglxd, swfjsgz, kbjghq );
                    }
                    swdf = GenUtil.getAvgPrice( pbbj, jgjsbl, zpl1kf, fpl1kf, pjj );
                } else if ("1".equals( zhpbswgz )) {//基数价
                    swdf = GenUtil.getBasePrice( jzj, zpl1kf, fpl1kf, pbbj );
                }
                resultMap.put( "gysmc", gysmc );
                resultMap.put( "gysmcname", gysmcname );
                resultMap.put( "tbwsze", wsbj );
                resultMap.put( "fktjxs", fkxs );
                resultMap.put( "zfxsxs", zfxs );
                resultMap.put( "slId", slId );
                resultMap.put( "sl", sl );
                resultMap.put( "wspbbj", pbbj );
                resultMap.put( "swdf", swdf );
                dataList1.add( resultMap );
            }
            /* 技术分计算规则*/
            baseBean.writeLog( "----------------技术分计算规则--------------" );
            String sql2 = "select gysmc,wm_concat(pfr) as pfr, wm_concat(pf) as pf from (\n" +
                    "SELECT t.pfr,REGEXP_SUBSTR(to_char(t1.gysmc), '[^,]+', 1, LEVEL) gysmc,\n" +
                    "sum(REGEXP_SUBSTR(to_char(t1.pf), '[^,]+', 1, LEVEL)) as pf\n" +
                    "FROM  "+dfb+" t left join "+dfb+"_dt1 t1\n" +
                    "on t.id=t1.mainid where lc=? and cglxd=?\n" +
                    "CONNECT BY LEVEL <= REGEXP_COUNT(to_char(t1.gysmc), '[^,]+')\n" +
                    "       AND t1.ROWID = PRIOR t1.ROWID\n" +
                    "       AND PRIOR DBMS_RANDOM.VALUE IS NOT NULL\n" +
                    "group by REGEXP_SUBSTR(to_char(t1.gysmc), '[^,]+', 1, LEVEL),t.pfr\n" +
                    "order by t.pfr)\n" +
                    "group by gysmc";
            rs.executeQuery( sql2, lc, cglxd );
            rs.writeLog( sql2, lc + "," + cglxd );
            while (rs.next()) {
                Map<String, String> resultMap1 = new HashMap<>();
                Map<String, String> resultMap2 = new HashMap<>();
                String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                String gysmcname = GenUtil.getId2Gysmc( gysmc );
                String pf = Util.null2String( rs.getString( "pf" ) );
                String pfr = Util.null2String( rs.getString( "pfr" ) );
                String jsdf = GenUtil.getTechCalRule( lc, cglxd, jsfjsgz, gysmc, dfb );
                resultMap1.put( "pfrs", pfr );
                resultMap1.put( "gysmc", gysmc );
                resultMap1.put( "gysmcname", gysmcname );
                resultMap1.put( "jsdf", jsdf );
                resultMap1.put( "pf", pf );
                dataList2.add( resultMap1 );
                baseBean.writeLog( "dataList2=", dataList2.toString() );
                String swdf = "";
                String wstbbj = "";
                for (Map<String, String> mapList : dataList1) {
                    for (String key : mapList.keySet()) {
                        if (key.equals( "gysmc" )) {
                            if (gysmc.equals( mapList.get( key ) )) {
                                swdf = mapList.get( "swdf" );
                                wstbbj = mapList.get( "tbwsze" );
                            }
                        }
                    }
                }

                String fktjkxx = GenUtil.getFktjkxxId( gysmc, lc, cglxd, gystb );
                String fktjkxxname = GenUtil.getFktjkxxName( fktjkxx );
                String zhdf = CalUtil.fAdd( CalUtil.fMultiply( swdf, swbl ), CalUtil.fMultiply( jsdf, jsbl ) );
                resultMap2.put( "swdf", swdf );
                resultMap2.put( "wstbbj", wstbbj );
                resultMap2.put( "gysmc", gysmc );
                resultMap2.put( "gysmcname", gysmcname );
                resultMap2.put( "jsdf", jsdf );
                resultMap2.put( "zhdf", zhdf );
                resultMap2.put( "fktjkxx", fktjkxx );
                resultMap2.put( "fktjkxxname", fktjkxxname );
                dataList3.add( resultMap2 );
            }
            apidatas.put( "dataList1", dataList1 );
            apidatas.put( "dataList2", dataList2 );
            apidatas.put( "dataList3", dataList3 );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单获取流程状态更新任务状态
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/updateCgrwStat")
    @Produces({MediaType.TEXT_PLAIN})
    public String updateCgrwStat(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            String rwdid = Util.null2String( request.getParameter( "rwdid" ) );
            String cglx = Util.null2String( request.getParameter( "cglx" ) );
            RecordSet rs = new RecordSet();
            String cgrwTable = GenUtil.getCgrwTableType( cglx );
            String sql = "update " + cgrwTable + " set rwzt=1 where id in (" + rwdid + ")";
            rs.executeUpdate( sql );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单、表名获取任务单ID更新任务状态、更新项目状态
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getRwdId2Cglx")
    @Produces({MediaType.TEXT_PLAIN})
    public String getRwdId2Cglx(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            String table = Util.null2String( request.getParameter( "table" ) );
            BaseBean baseBean = new BaseBean();
            String formtable = baseBean.getPropValue( "SrmWfTab", table );
            RecordSet rs = new RecordSet();
            String sql = "select t.cglx,wm_concat(t1.rwdid) as rwdids from " + formtable + " t left join " +
                    formtable + "_dt2 t1 on t.id=t1.mainid where t.requestid=? group by t.cglx";
            rs.executeQuery( sql, cglxd );
            rs.next();
            String cglx = Util.null2String( rs.getString( "cglx" ) );
            String rwdids = Util.null2String( rs.getString( "rwdids" ) );
            String cgrwTable = GenUtil.getCgrwTableType( cglx );
            String sql1 = "update " + cgrwTable + " set rwzt=0 where id in (" + rwdids + ")";
            rs.executeUpdate( sql1 );
            String sql2 = "update " + formtable + " set xmzt=2 where requestid=?";
            rs.executeUpdate( sql2, cglxd );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 统计采购任务状态为未生成的个数
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getCgrwTotal")
    @Produces({MediaType.TEXT_PLAIN})
    public String getCgrwTotal(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            String xqly = Util.null2String( request.getParameter( "xqly" ) );
            BaseBean baseBean = new BaseBean();
            String cgxqwl = baseBean.getPropValue( "SrmMdTab", "cgxqwl" );
            String cgxqgc = baseBean.getPropValue( "SrmMdTab", "cgxqgc" );
            String cgxqzl = baseBean.getPropValue( "SrmMdTab", "cgxqzl" );
            String cgxqys = baseBean.getPropValue( "SrmMdTab", "cgxqys" );
            String cgxqfw = baseBean.getPropValue( "SrmMdTab", "cgxqfw" );
            String cgrwwl = baseBean.getPropValue( "SrmMdTab", "cgrwwl" );
            String cgrwgc = baseBean.getPropValue( "SrmMdTab", "cgrwgc" );
            String cgrwzl = baseBean.getPropValue( "SrmMdTab", "cgrwzl" );
            String cgrwys = baseBean.getPropValue( "SrmMdTab", "cgrwys" );
            String cgrwfw = baseBean.getPropValue( "SrmMdTab", "cgrwfw" );
            JSONObject datas = new JSONObject();
            RecordSet rs = new RecordSet();
            //物料需求
            String sql1 = "select count(id) from " + cgxqwl + " where xqly=? and fplx=0";
            rs.executeQuery( sql1, xqly );
            rs.next();
            String wlCgxqCounts = Util.null2String( rs.getString( 1 ) );
            datas.put( "wlCgxqCounts", wlCgxqCounts );
            //工程需求
            String sql2 = "select count(id) from " + cgxqgc + " where xqly=? and fplx=0";
            rs.executeQuery( sql2, xqly );
            rs.next();
            String gcCgxqCounts = Util.null2String( rs.getString( 1 ) );
            datas.put( "gcCgxqCounts", gcCgxqCounts );
            //租赁需求
            String sql3 = "select count(id) from " + cgxqzl + " where xqly=? and fplx=0";
            rs.executeQuery( sql3, xqly );
            rs.next();
            String zlCgxqCounts = Util.null2String( rs.getString( 1 ) );
            datas.put( "zlCgxqCounts", zlCgxqCounts );
            //运输需求
            String sql4 = "select count(id) from " + cgxqys + " where xqly=? and fplx=0";
            rs.executeQuery( sql4, xqly );
            rs.next();
            String ysCgxqCounts = Util.null2String( rs.getString( 1 ) );
            datas.put( "ysCgxqCounts", ysCgxqCounts );
            //服务需求
            String sql5 = "select count(id) from " + cgxqfw + " where xqly=? and fplx=0";
            rs.executeQuery( sql5, xqly );
            rs.next();
            String fwCgxqCounts = Util.null2String( rs.getString( 1 ) );
            datas.put( "fwCgxqCounts", fwCgxqCounts );
            //物料任务
            String sql6 = "select count(id) from " + cgrwwl + " where xqly=? and rwzt=0";
            rs.executeQuery( sql6, xqly );
            rs.next();
            String wlCgrwCounts = Util.null2String( rs.getString( 1 ) );
            datas.put( "wlCgrwCounts", wlCgrwCounts );
            //工程任务
            String sql7 = "select count(id) from " + cgrwgc + " where xqly=? and rwzt=0";
            rs.executeQuery( sql7, xqly );
            rs.next();
            String gcCgrwCounts = Util.null2String( rs.getString( 1 ) );
            datas.put( "gcCgrwCounts", gcCgrwCounts );
            //租赁任务
            String sql8 = "select count(id) from " + cgrwzl + " where xqly=? and rwzt=0";
            rs.executeQuery( sql8, xqly );
            rs.next();
            String zlCgrwCounts = Util.null2String( rs.getString( 1 ) );
            datas.put( "zlCgrwCounts", zlCgrwCounts );
            //运输任务
            String sql9 = "select count(id) from " + cgrwys + " where xqly=? and rwzt=0";
            rs.executeQuery( sql9, xqly );
            rs.next();
            String ysCgrwCounts = Util.null2String( rs.getString( 1 ) );
            datas.put( "ysCgrwCounts", ysCgrwCounts );
            //服务任务
            String sql10 = "select count(id) from " + cgrwfw + " where xqly=? and rwzt=0";
            rs.executeQuery( sql10, xqly );
            rs.next();
            String fwCgrwCounts = Util.null2String( rs.getString( 1 ) );
            datas.put( "fwCgrwCounts", fwCgrwCounts );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 获取招标采购立项流程招标方式
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getZbcglxWfData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getZbcglxWfData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            BaseBean baseBean = new BaseBean();
            String zbcglx = baseBean.getPropValue( "SrmWfTab", "zbcglx" );
            RecordSet rs = new RecordSet();
            JSONObject datas = new JSONObject();
            //物料需求
            String sql1 = "select zbfs,zdtbdws,xmzt from " + zbcglx + " where requestid=?";
            rs.executeQuery( sql1, cglxd );
            rs.next();
            String zbfs = Util.null2String( rs.getString( "zbfs" ) );//招标方式
            int zdtbdws = Util.getIntValue( rs.getString( "zdtbdws" ) );//最低投标单位数
            int xmzt = Util.getIntValue( rs.getString( "xmzt" ) );//项目状态
            datas.put( "zbfs", zbfs );
            datas.put( "zdtbdws", zdtbdws );
            datas.put( "xmzt", xmzt );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 获取供应商报名个数
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getGysbmCounts")
    @Produces({MediaType.TEXT_PLAIN})
    public String getGysbmCounts(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            BaseBean baseBean = new BaseBean();
            String gysbm = baseBean.getPropValue( "SrmWfTab", "gysbm" );
            RecordSet rs = new RecordSet();
            JSONObject datas = new JSONObject();
            //物料需求
            String sql = "select max(tbjzsj) as tbjzsj from " + gysbm + " where cglxd=?";
            rs.executeQuery( sql, cglxd );
            rs.next();
            String tbjzsj = Util.null2String( rs.getString( "tbjzsj" ) );
            datas.put( "tbjzsj", tbjzsj );
            String sql1 = "select count(t1.requestid) as counts from " + gysbm + " t1 left join workflow_requestbase t2 \n" +
                    "on t1.requestid=t2.requestid where cglxd=? and t2.currentnodetype=3";
            rs.executeQuery( sql1, cglxd );
            rs.next();
            int counts = Util.getIntValue( rs.getString( "counts" ) );
            datas.put( "counts", counts );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 获取短名单邀请回执个数，查看邀请回执各个数，回执完成个数
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getDmdyqCounts")
    @Produces({MediaType.TEXT_PLAIN})
    public String getDmdyqCounts(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String yqhz = baseBean.getPropValue( "SrmWfTab", "yqhz" );
            int totalCounts = 0;//邀请回执总流程数
            int viewCounts = 0;//流程查看数
            int compCounts = 0;//流程归档数
            String sql1 = "select count(iscomplete) AS iscomplete from (\n" +
                    "select t1.iscomplete from workflow_currentoperator t1 \n" +
                    "left join " + yqhz + " t2 on t1.requestid=t2.requestid where t2.cglxd=? and t1.iscomplete=1\n" +
                    "group by t1.requestid,t1.iscomplete,t2.gysmc) ";
            rs.executeQuery( sql1, cglxd );
            if (rs.next()) {
                compCounts = Util.getIntValue( rs.getString( "iscomplete" ) );
            }

            String sql2 = "select count(viewtype)AS viewtype from (\n" +
                    "select t1.viewtype from workflow_currentoperator t1 \n" +
                    "left join " + yqhz + " t2 on t1.requestid=t2.requestid where t2.cglxd=? and t1.viewtype='-2'\n" +
                    "group by t1.requestid,t1.viewtype,t2.gysmc ) ";
            rs.executeQuery( sql2, cglxd );
            if (rs.next()) {
                viewCounts = Util.getIntValue( rs.getString( "viewtype" ) );
            }
            String sql3 = "select count(requestid)AS total from (\n" +
                    "select t1.requestid from workflow_currentoperator t1 \n" +
                    "left join " + yqhz + " t2 on t1.requestid=t2.requestid where t2.cglxd=? \n" +
                    "group by t1.requestid,t2.gysmc ) ";
            rs.executeQuery( sql3, cglxd );
            if (rs.next()) {
                totalCounts = Util.getIntValue( rs.getString( "total" ) );
            }

            datas.put( "totalCounts", totalCounts );
            datas.put( "viewCounts", viewCounts );
            datas.put( "compCounts", compCounts );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 获取供应商投标邀请回执个数，查看邀请回执各个数，回执完成个数
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getGystbCounts")
    @Produces({MediaType.TEXT_PLAIN})
    public String getGystbCounts(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            String lc = Util.null2String( request.getParameter( "lc" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String gystb = baseBean.getPropValue( "SrmWfTab", "gystb" );
            int totalCounts = 0;//邀请回执总流程数
            int viewCounts = 0;//流程查看数
            int compCounts = 0;//流程归档数
            String sql1 = "select count(iscomplete) AS iscomplete from (\n" +
                    "select t1.iscomplete from workflow_currentoperator t1 \n" +
                    "left join " + gystb + " t2 on t1.requestid=t2.requestid where t2.cglxd=? and t2.lc=? and t1.iscomplete=1\n" +
                    "group by t1.requestid,t1.iscomplete,t2.gysmc) ";
            rs.executeQuery( sql1, cglxd, lc );
            if (rs.next()) {
                compCounts = Util.getIntValue( rs.getString( "iscomplete" ) );
            }

            String sql2 = "select count(viewtype)AS viewtype from (\n" +
                    "select t1.viewtype from workflow_currentoperator t1 \n" +
                    "left join " + gystb + " t2 on t1.requestid=t2.requestid where t2.cglxd=? and t2.lc=? and t1.viewtype='-2'\n" +
                    "group by t1.requestid,t1.viewtype,t2.gysmc ) ";
            rs.executeQuery( sql2, cglxd, lc );
            if (rs.next()) {
                viewCounts = Util.getIntValue( rs.getString( "viewtype" ) );
            }
            String sql3 = "select count(requestid)AS total from (\n" +
                    "select t1.requestid from workflow_currentoperator t1 \n" +
                    "left join " + gystb + " t2 on t1.requestid=t2.requestid where t2.cglxd=? and t2.lc=?\n" +
                    "group by t1.requestid,t2.gysmc ) ";
            rs.executeQuery( sql3, cglxd, lc );
            if (rs.next()) {
                totalCounts = Util.getIntValue( rs.getString( "total" ) );
            }

            datas.put( "totalCounts", totalCounts );
            datas.put( "viewCounts", viewCounts );
            datas.put( "compCounts", compCounts );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 获取发布公告截至时间
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getFbggData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getFbggData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String zbfbgg = baseBean.getPropValue( "SrmWfTab", "zbfbgg" );
            String sql1 = "select concat(bmjzsj,':00') as bmjzsj from (select t1.bmjzsj from " + zbfbgg + " t1 \n" +
                    "left join workflow_requestbase t2 on t1.requestid=t2.requestid \n" +
                    "where t1.cglxd=? and t2.currentnodetype = 3 order by t1.id desc) where rownum<2";
            rs.executeQuery( sql1, cglxd );
            rs.next();
            String bmjzsj = Util.null2String( rs.getString( "bmjzsj" ) );
            datas.put( "bmjzsj", bmjzsj );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 从发起评标流程获取轮次获取投标截至时间
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getFqpbTbjzrq")
    @Produces({MediaType.TEXT_PLAIN})
    public String getFqpbTbjzrq(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String fqpb = baseBean.getPropValue( "SrmWfTab", "fqpb" );
            String sql = "select max(tbjzrq) from " + fqpb + " where  cglxd=?";
            rs.executeQuery( sql, cglxd );
            rs.next();
            String tbjzrq = Util.null2String( rs.getString( 1 ) );
            datas.put( "tbjzrq", tbjzrq );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 从发起评标流程获取轮次, 截至时间、评标方式、综合法
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getFqpbData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getFqpbData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            String lc = Util.null2String( request.getParameter( "lc" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String fqpb = baseBean.getPropValue( "SrmWfTab", "fqpb" );
            String sql = "select tbjzrq,cglx,pbfs,zhpbswgz from " + fqpb + " where  cglxd=? and lc=?";
            rs.executeQuery( sql, cglxd, lc );
            rs.next();
            String tbjzrq = Util.null2String( rs.getString( "tbjzrq" ) );
            String cglx = Util.null2String( rs.getString( "cglx" ) );
            String pbfs = Util.null2String( rs.getString( "pbfs" ) );
            String zhpbswgz = Util.null2String( rs.getString( "zhpbswgz" ) );
            datas.put( "tbjzrq", tbjzrq );
            datas.put( "cglx", cglx );
            datas.put( "pbfs", pbfs );
            datas.put( "zhpbswgz", zhpbswgz );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单判断发起招标流程是否存在在途流程
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/haveIsFinish")
    @Produces({MediaType.TEXT_PLAIN})
    public String haveIsFinish(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            boolean flag = false;
            JSONObject datas = new JSONObject();
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            String lc = Util.null2String( request.getParameter( "lc" ) );
            String requestid = Util.null2String( request.getParameter( "requestid" ) );
            String pbjghq = baseBean.getPropValue( "SrmWfTab", "pbjghq" );
            String fqpb = baseBean.getPropValue( "SrmWfTab", "fqpb" );
            String sql = "select m.requestid,currentnodetype from " + fqpb + " m left join workflow_requestbase n " +
                    "on m.requestid=n.requestid where m.cglxd=? and m.requestid !=? and m.lc=?";
            rs.executeQuery( sql, cglxd, requestid, lc );
            if (rs.next()) {//已经存在流程
                int currentnodetype = Util.getIntValue( rs.getString( "currentnodetype" ) );
                if (currentnodetype < 3) {//流程已归档
                    flag = true;
                } else {
                    String sql1 = "select m.requestid from " + pbjghq + " m left join workflow_requestbase n \n" +
                            "on m.requestid=n.requestid where m.cglxd=? and n.currentnodetype=3 and m.lc=? and m.xbcz=2";
                    rs.executeQuery( sql1, cglxd, lc );
                    if (!rs.next()) {
                        flag = true;
                    }
                }
            }
            datas.put( "flag", flag );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据轮次, 采购立项单，采购类型获取对应的明细表
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getGystbDtlData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getGystbDtlData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            String lc = Util.null2String( request.getParameter( "lc" ) );
            String cglx = Util.null2String( request.getParameter( "cglx" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String gystb = baseBean.getPropValue( "SrmWfTab", "gystb" );
            List<Map<String, String>> dataList = new ArrayList<>();
            String sql = "";
            switch (cglx) {
                case "0"://采购需求明细-物料类
                    sql = "select a.cglxd,a.gysmc,b.wlbm,b.wlmc,b.cms,b.sl,b.wsdj,\n" +
                            "       (select sum(t1.wsdj)/count(t.gysmc) from " + gystb + " t," + gystb + "_dt4 t1 where t.id=t1.mainid and t1.wlbm=b.wlbm and a.cglxd=t.cglxd and t.lc=a.lc) as wspjj,\n" +
                            "       (select min(t1.wsdj) from " + gystb + " t," + gystb + "_dt4 t1 where t.id=t1.mainid and t1.wlbm=b.wlbm and a.cglxd=t.cglxd and t.lc=a.lc) as wszdj,\n" +
                            "       round((100*(b.wsdj-(select sum(t1.wsdj)/count(t.gysmc) from " + gystb + " t," + gystb + "_dt4 t1 where t.id=t1.mainid and t1.wlbm=b.wlbm and a.cglxd=t.cglxd and t.lc=a.lc))/b.wsdj),2) as plpjj,\n" +
                            "       round((100*(b.wsdj-(select min(t1.wsdj) from " + gystb + " t," + gystb + "_dt4 t1 where t.id=t1.mainid and t1.wlbm=b.wlbm and a.cglxd=t.cglxd and t.lc=a.lc))/b.wsdj),2) as plzdj\n" +
                            "from " + gystb + " a," + gystb + "_dt4 b\n" +
                            "where a.id=b.mainid and a.cglxd=? and a.lc=?";
                    rs.executeQuery( sql, cglxd, lc );
                    while (rs.next()) {
                        Map<String, String> dataMap = new HashMap<>();
                        String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                        String gysmcname = GenUtil.getId2Gysmc( gysmc );
                        String wlbm = Util.null2String( rs.getString( "wlbm" ) );
                        String wlmc = Util.null2String( rs.getString( "wlmc" ) );
                        String cms = Util.null2String( rs.getString( "cms" ) );
                        String sl = Util.null2String( rs.getString( "sl" ) );
                        String wsdj = Util.null2String( rs.getString( "wsdj" ) );
                        String wspjj = Util.null2String( rs.getString( "wspjj" ) );
                        String wszdj = Util.null2String( rs.getString( "wszdj" ) );
                        String plpjj = Util.null2String( rs.getString( "plpjj" ) );
                        String plzdj = Util.null2String( rs.getString( "plzdj" ) );
                        dataMap.put( "gysmc", gysmc );
                        dataMap.put( "gysmcname", gysmcname );
                        dataMap.put( "wlbm", wlbm );
                        dataMap.put( "cms", cms );
                        dataMap.put( "sl", sl );
                        dataMap.put( "wsdj", wsdj );
                        dataMap.put( "wlmc", wlmc );
                        dataMap.put( "wspjj", wspjj );
                        dataMap.put( "wszdj", wszdj );
                        dataMap.put( "plpjj", plpjj );
                        dataMap.put( "plzdj", plzdj );
                        dataList.add( dataMap );
                    }
                    break;
                case "1"://采购需求明细-工程类
                    sql = "select a.cglxd,a.gysmc,b.wlbm,b.wlmc,b.cms,b.sl,b.wsdj,\n" +
                            "       (select sum(t1.wsdj)/count(t.gysmc) from " + gystb + " t," + gystb + "_dt5 t1 where t.id=t1.mainid and t1.wlbm=b.wlbm and a.cglxd=t.cglxd and t.lc=a.lc) as wspjj,\n" +
                            "       (select min(t1.wsdj) from " + gystb + " t," + gystb + "_dt5 t1 where t.id=t1.mainid and t1.wlbm=b.wlbm and a.cglxd=t.cglxd and t.lc=a.lc) as wszdj,\n" +
                            "       round((100*(b.wsdj-(select sum(t1.wsdj)/count(t.gysmc) from " + gystb + " t," + gystb + "_dt5 t1 where t.id=t1.mainid and t1.wlbm=b.wlbm and a.cglxd=t.cglxd and t.lc=a.lc))/b.wsdj),2) as plpjj,\n" +
                            "       round((100*(b.wsdj-(select min(t1.wsdj) from " + gystb + " t," + gystb + "_dt5 t1 where t.id=t1.mainid and t1.wlbm=b.wlbm and a.cglxd=t.cglxd and t.lc=a.lc))/b.wsdj),2) as plzdj\n" +
                            "from " + gystb + " a," + gystb + "_dt5 b\n" +
                            "where a.id=b.mainid and a.cglxd=? and a.lc=?";
                    rs.executeQuery( sql, cglxd, lc );
                    while (rs.next()) {
                        Map<String, String> dataMap = new HashMap<>();
                        String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                        String gysmcname = GenUtil.getId2Gysmc( gysmc );
                        String wlbm = Util.null2String( rs.getString( "wlbm" ) );
                        String cms = Util.null2String( rs.getString( "cms" ) );
                        String sl = Util.null2String( rs.getString( "sl" ) );
                        String wsdj = Util.null2String( rs.getString( "wsdj" ) );
                        String wlmc = Util.null2String( rs.getString( "wlmc" ) );
                        String wspjj = Util.null2String( rs.getString( "wspjj" ) );
                        String wszdj = Util.null2String( rs.getString( "wszdj" ) );
                        String plpjj = Util.null2String( rs.getString( "plpjj" ) );
                        String plzdj = Util.null2String( rs.getString( "plzdj" ) );
                        dataMap.put( "gysmc", gysmc );
                        dataMap.put( "gysmcname", gysmcname );
                        dataMap.put( "wlbm", wlbm );
                        dataMap.put( "cms", cms );
                        dataMap.put( "sl", sl );
                        dataMap.put( "wsdj", wsdj );
                        dataMap.put( "wlmc", wlmc );
                        dataMap.put( "wspjj", wspjj );
                        dataMap.put( "wszdj", wszdj );
                        dataMap.put( "plpjj", plpjj );
                        dataMap.put( "plzdj", plzdj );
                        dataList.add( dataMap );

                    }
                    break;
                case "2"://采购需求明细-租赁类
                    sql = "select a.cglxd,a.gysmc,b.mc,b.ggxh,b.sl,b.wsdj,\n" +
                            "       (select sum(t1.wsdj)/count(t.gysmc) from " + gystb + " t," + gystb + "_dt6 t1 where t.id=t1.mainid and t1.mc=b.mc and a.cglxd=t.cglxd and t.lc=a.lc) as wspjj,\n" +
                            "       (select min(t1.wsdj) from " + gystb + " t," + gystb + "_dt6 t1 where t.id=t1.mainid and t1.mc=b.mc and a.cglxd=t.cglxd and t.lc=a.lc) as wszdj,\n" +
                            "       round((100*(b.wsdj-(select sum(t1.wsdj)/count(t.gysmc) from " + gystb + " t," + gystb + "_dt6 t1 where t.id=t1.mainid and t1.mc=b.mc and a.cglxd=t.cglxd and t.lc=a.lc))/b.wsdj),2) as plpjj,\n" +
                            "       round((100*(b.wsdj-(select min(t1.wsdj) from " + gystb + " t," + gystb + "_dt6 t1 where t.id=t1.mainid and t1.mc=b.mc and a.cglxd=t.cglxd and t.lc=a.lc))/b.wsdj),2) as plzdj\n" +
                            "from " + gystb + " a," + gystb + "_dt6 b\n" +
                            "where a.id=b.mainid and a.cglxd=? and a.lc=?";
                    rs.executeQuery( sql, cglxd, lc );
                    while (rs.next()) {
                        Map<String, String> dataMap = new HashMap<>();
                        String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                        String gysmcname = GenUtil.getId2Gysmc( gysmc );
                        String mc = Util.null2String( rs.getString( "mc" ) );
                        String ggxh = Util.null2String( rs.getString( "ggxh" ) );
                        String sl = Util.null2String( rs.getString( "sl" ) );
                        String wsdj = Util.null2String( rs.getString( "wsdj" ) );
                        String wspjj = Util.null2String( rs.getString( "wspjj" ) );
                        String wszdj = Util.null2String( rs.getString( "wszdj" ) );
                        String plpjj = Util.null2String( rs.getString( "plpjj" ) );
                        String plzdj = Util.null2String( rs.getString( "plzdj" ) );
                        dataMap.put( "gysmc", gysmc );
                        dataMap.put( "gysmcname", gysmcname );
                        dataMap.put( "mc", mc );
                        dataMap.put( "ggxh", ggxh );
                        dataMap.put( "sl", sl );
                        dataMap.put( "wsdj", wsdj );
                        dataMap.put( "wspjj", wspjj );
                        dataMap.put( "wszdj", wszdj );
                        dataMap.put( "plpjj", plpjj );
                        dataMap.put( "plzdj", plzdj );
                        dataList.add( dataMap );
                    }
                    break;
                case "3"://报价明细-运输类
                    sql = "select a.cglxd,a.gysmc,b.ysnr,b.sl,b.wsdj,\n" +
                            "       (select sum(t1.wsdj)/count(t.gysmc) from " + gystb + " t," + gystb + "_dt8 t1 where t.id=t1.mainid and t1.ysnr=b.ysnr and a.cglxd=t.cglxd and t.lc=a.lc) as wspjj,\n" +
                            "       (select min(t1.wsdj) from " + gystb + " t," + gystb + "_dt8 t1 where t.id=t1.mainid and t1.ysnr=b.ysnr and a.cglxd=t.cglxd and t.lc=a.lc) as wszdj,\n" +
                            "       round((100*(b.wsdj-(select sum(t1.wsdj)/count(t.gysmc) from " + gystb + " t," + gystb + "_dt8 t1 where t.id=t1.mainid and t1.ysnr=b.ysnr and a.cglxd=t.cglxd and t.lc=a.lc))/b.wsdj),2) as plpjj,\n" +
                            "       round((100*(b.wsdj-(select min(t1.wsdj) from " + gystb + " t," + gystb + "_dt8 t1 where t.id=t1.mainid and t1.ysnr=b.ysnr and a.cglxd=t.cglxd and t.lc=a.lc))/b.wsdj),2) as plzdj\n" +
                            "from " + gystb + " a," + gystb + "_dt8 b\n" +
                            "where a.id=b.mainid and a.cglxd=? and a.lc=?";
                    rs.executeQuery( sql, cglxd, lc );
                    while (rs.next()) {
                        Map<String, String> dataMap = new HashMap<>();
                        String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                        String gysmcname = GenUtil.getId2Gysmc( gysmc );
                        String ysnr = Util.null2String( rs.getString( "ysnr" ) );
                        String sl = Util.null2String( rs.getString( "sl" ) );
                        String wsdj = Util.null2String( rs.getString( "wsdj" ) );
                        String wspjj = Util.null2String( rs.getString( "wspjj" ) );
                        String wszdj = Util.null2String( rs.getString( "wszdj" ) );
                        String plpjj = Util.null2String( rs.getString( "plpjj" ) );
                        String plzdj = Util.null2String( rs.getString( "plzdj" ) );
                        dataMap.put( "gysmc", gysmc );
                        dataMap.put( "gysmcname", gysmcname );
                        dataMap.put( "ysnr", ysnr );
                        dataMap.put( "sl", sl );
                        dataMap.put( "wsdj", wsdj );
                        dataMap.put( "wspjj", wspjj );
                        dataMap.put( "wszdj", wszdj );
                        dataMap.put( "plpjj", plpjj );
                        dataMap.put( "plzdj", plzdj );
                        dataList.add( dataMap );
                    }
                    break;
                case "4"://采购需求明细-服务类
                    sql = "select a.cglxd,a.gysmc,b.fwnr,b.fwyq,b.sl,b.wsdj,\n" +
                            "       (select sum(t1.wsdj)/count(t.gysmc) from " + gystb + " t," + gystb + "_dt9 t1 where t.id=t1.mainid and t1.fwnr=b.fwnr and a.cglxd=t.cglxd and t.lc=a.lc) as wspjj,\n" +
                            "       (select min(t1.wsdj) from " + gystb + " t," + gystb + "_dt9 t1 where t.id=t1.mainid and t1.fwnr=b.fwnr and a.cglxd=t.cglxd and t.lc=a.lc) as wszdj,\n" +
                            "       round((100*(b.wsdj-(select sum(t1.wsdj)/count(t.gysmc) from " + gystb + " t," + gystb + "_dt9 t1 where t.id=t1.mainid and t1.fwnr=b.fwnr and a.cglxd=t.cglxd and t.lc=a.lc))/b.wsdj),2) as plpjj,\n" +
                            "       round((100*(b.wsdj-(select min(t1.wsdj) from " + gystb + " t," + gystb + "_dt9 t1 where t.id=t1.mainid and t1.fwnr=b.fwnr and a.cglxd=t.cglxd and t.lc=a.lc))/b.wsdj),2) as plzdj\n" +
                            "from " + gystb + " a," + gystb + "_dt9 b\n" +
                            "where a.id=b.mainid and a.cglxd=? and a.lc=?";
                    rs.executeQuery( sql, cglxd, lc );
                    while (rs.next()) {
                        Map<String, String> dataMap = new HashMap<>();
                        String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                        String gysmcname = GenUtil.getId2Gysmc( gysmc );
                        String fwnr = Util.null2String( rs.getString( "fwnr" ) );
                        String fwyq = Util.null2String( rs.getString( "fwyq" ) );
                        String wsdj = Util.null2String( rs.getString( "wsdj" ) );
                        String sl = Util.null2String( rs.getString( "sl" ) );
                        String wspjj = Util.null2String( rs.getString( "wspjj" ) );
                        String wszdj = Util.null2String( rs.getString( "wszdj" ) );
                        String plpjj = Util.null2String( rs.getString( "plpjj" ) );
                        String plzdj = Util.null2String( rs.getString( "plzdj" ) );
                        dataMap.put( "gysmc", gysmc );
                        dataMap.put( "gysmcname", gysmcname );
                        dataMap.put( "fwnr", fwnr );
                        dataMap.put( "fwyq", fwyq );
                        dataMap.put( "wsdj", wsdj );
                        dataMap.put( "sl", sl );
                        dataMap.put( "wspjj", wspjj );
                        dataMap.put( "wszdj", wszdj );
                        dataMap.put( "plpjj", plpjj );
                        dataMap.put( "plzdj", plzdj );
                        dataList.add( dataMap );
                    }
                    break;
            }
            datas.put( "lc", lc );
            apidatas.put( "dataList", dataList );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据轮次, 采购立项单获取评标结果会签的下一步操作
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getPbjghqData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getPbjghqData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            String lc = Util.null2String( request.getParameter( "lc" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String pbjghq = baseBean.getPropValue( "SrmWfTab", "pbjghq" );
            String sql = "select xbcz from " + pbjghq + " where cglxd=? and lc=?";
            rs.executeQuery( sql, cglxd, lc );
            rs.next();
            String xbcz = Util.null2String( rs.getString( "xbcz" ) );
            datas.put( "xbcz", xbcz );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据轮次, 采购立项单，采购类型获取对应的明细表
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getGystbDtl2BjbData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getGystbDtl2BjbData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            String lc = Util.null2String( request.getParameter( "lc" ) );
            String cglx = Util.null2String( request.getParameter( "cglx" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String gystb = baseBean.getPropValue( "SrmWfTab", "gystb" );
            String kbjghq = baseBean.getPropValue( "SrmWfTab", "kbjghq" );
            List<Map<String, String>> dataList = new ArrayList<>();
            String sql = "";
            switch (cglx) {
                case "0"://采购需求明细-物料类
                    sql = "select a.wlbm,a.wlmc,a.cms,a.sl,wm_concat(a.gysmc)as gysmcs,wm_concat(a.wsdj)as wsdjs,a.xqbh from \n" +
                            "(select t1.wlbm,t1.wlmc,t1.cms,t1.sl,t.gysmc,t.cglxd,t.lc,t1.wsdj,t1.xqbh from " + gystb + " t left join " + gystb + "_dt4 t1 on t.id=t1.mainid)a,\n" +
                            "(select t.cglxd,t.lc,t1.gys from " + kbjghq + " t left join " + kbjghq + "_dt1 t1 on t.id=t1.mainid where t1.sfyxtb=0)b\n" +
                            "where a.cglxd=b.cglxd and a.lc=b.lc and a.gysmc=b.gys and a.cglxd=? and a.lc = ? " +
                            "group by a.wlbm,a.wlmc,a.cms,a.sl,a.xqbh";
                    rs.executeQuery( sql, cglxd, lc );
                    while (rs.next()) {
                        Map<String, String> dataMap = new HashMap<>();
                        String gysmcs = Util.null2String( rs.getString( "gysmcs" ) );
                        String gysmcname = GenUtil.getId2Gysmcs( gysmcs );
                        String wlbm = Util.null2String( rs.getString( "wlbm" ) );
                        String wlmc = Util.null2String( rs.getString( "wlmc" ) );
                        String cms = Util.null2String( rs.getString( "cms" ) );
                        String sl = Util.null2String( rs.getString( "sl" ) );
                        String wsdjs = Util.null2String( rs.getString( "wsdjs" ) );
                        dataMap.put( "gysmcname", gysmcname );
                        dataMap.put( "wlbm", wlbm );
                        dataMap.put( "cms", cms );
                        dataMap.put( "sl", sl );
                        dataMap.put( "wsdjs", wsdjs );
                        dataMap.put( "wlmc", wlmc );
                        dataList.add( dataMap );
                    }
                    break;
                case "1"://采购需求明细-工程类
                    sql = "select a.dwgc,a.zdwgc,a.fbgc,a.zfbgc,wm_concat(a.sbf) as sbfs,wm_concat(a.zcf) as zcfs,wm_concat(a.rgf) as rgfs,\n" +
                            "wm_concat(a.fcf) as fcfs,wm_concat(a.jxf) as jxfs,wm_concat(a.sbf+a.zcf+a.rgf+a.fcf+a.jxf) as xjs,wm_concat(a.gysmc) as gysmcs\n" +
                            "from (select t1.dwgc,t1.zdwgc,t1.fbgc,t1.zfbgc,t1.sbf,t1.zcf,t1.rgf,t1.fcf,t1.jxf,t.gysmc,t.cglxd,t.lc from "+gystb+" t \n" +
                            "right join (select t5.dwgc,t5.zdwgc,t5.fbgc,t5.zfbgc,t5.rgf,t5.fcf,t5.jxf,t10.sbf,t10.zcf,t5.mainid \n" +
                            "from "+gystb+"_dt5 t5 left join "+gystb+"_dt10 t10 on t5.id=t10.wj)t1 on t.id=t1.mainid order by t.gysmc)a,\n" +
                            "(select t.cglxd,t.lc,t1.gys from "+kbjghq+" t left join "+kbjghq+"_dt1 t1 on t.id=t1.mainid where t1.sfyxtb=0)b \n" +
                            "where a.cglxd=b.cglxd and a.lc=b.lc and a.gysmc=b.gys and a.cglxd=? and a.lc = ?\n" +
                            "group by a.dwgc,a.zdwgc,a.fbgc,a.zfbgc";
                    rs.writeLog( "sql=" + sql );
                    rs.executeQuery( sql, cglxd, lc );
                    while (rs.next()) {
                        Map<String, String> dataMap = new HashMap<>();
                        String gysmcs = Util.null2String( rs.getString( "gysmcs" ) );
                        String gysmcname = GenUtil.getId2Gysmcs( gysmcs );
                        String dwgc = Util.null2String( rs.getString( "dwgc" ) );
                        String zdwgc = Util.null2String( rs.getString( "zdwgc" ) );
                        String fbgc = Util.null2String( rs.getString( "fbgc" ) );
                        String zfbgc = Util.null2String( rs.getString( "zfbgc" ) );
                        String sbfs = Util.null2String( rs.getString( "sbfs" ) );
                        String zcfs = Util.null2String( rs.getString( "zcfs" ) );
                        String rgfs = Util.null2String( rs.getString( "rgfs" ) );
                        String fcfs = Util.null2String( rs.getString( "fcfs" ) );
                        String jxfs = Util.null2String( rs.getString( "jxfs" ) );
                        String xjs = Util.null2String( rs.getString( "xjs" ) );
                        dataMap.put( "gysmcname", gysmcname );
                        dataMap.put( "dwgc", dwgc );
                        dataMap.put( "zdwgc", zdwgc );
                        dataMap.put( "fbgc", fbgc );
                        dataMap.put( "zfbgc", zfbgc );
                        dataMap.put( "sbfs", sbfs );
                        dataMap.put( "zcfs", zcfs );
                        dataMap.put( "rgfs", rgfs );
                        dataMap.put( "fcfs", fcfs );
                        dataMap.put( "jxfs", jxfs );
                        dataMap.put( "xjs", xjs );
                        dataList.add( dataMap );
                        rs.writeLog( "dataMap=", dataMap.toString() );
                    }
                    break;
                case "2"://采购需求明细-租赁类
                    sql = "select b.mc,b.ggxh,b.sl,wm_concat(a.gysmc)as gysmcs,wm_concat( b.wsdj)as wsdjs \n" +
                            "from " + gystb + " a," + gystb + "_dt6 b \n" +
                            "where a.id=b.mainid and a.cglxd=? and a.lc=? group by b.mc,b.ggxh,b.sl";
                    rs.executeQuery( sql, cglxd, lc );
                    while (rs.next()) {
                        Map<String, String> dataMap = new HashMap<>();
                        String gysmcs = Util.null2String( rs.getString( "gysmcs" ) );
                        String gysmcname = GenUtil.getId2Gysmcs( gysmcs );
                        String mc = Util.null2String( rs.getString( "mc" ) );
                        String ggxh = Util.null2String( rs.getString( "ggxh" ) );
                        String sl = Util.null2String( rs.getString( "sl" ) );
                        String wsdjs = Util.null2String( rs.getString( "wsdjs" ) );
                        dataMap.put( "gysmcname", gysmcname );
                        dataMap.put( "mc", mc );
                        dataMap.put( "ggxh", ggxh );
                        dataMap.put( "sl", sl );
                        dataMap.put( "wsdjs", wsdjs );
                        dataList.add( dataMap );
                    }
                    break;
                case "3"://报价明细-运输类
                    sql = "select b.ysnr,b.sl,wm_concat(a.gysmc)as gysmcs,wm_concat( b.wsdj)as wsdjs \n" +
                            "from " + gystb + " a," + gystb + "_dt8 b \n" +
                            "where a.id=b.mainid and a.cglxd=? and a.lc=? group by b.ysnr,b.sl";
                    rs.executeQuery( sql, cglxd, lc );
                    while (rs.next()) {
                        Map<String, String> dataMap = new HashMap<>();
                        String gysmcs = Util.null2String( rs.getString( "gysmcs" ) );
                        String gysmcname = GenUtil.getId2Gysmcs( gysmcs );
                        String ysnr = Util.null2String( rs.getString( "ysnr" ) );
                        String sl = Util.null2String( rs.getString( "sl" ) );
                        String wsdjs = Util.null2String( rs.getString( "wsdjs" ) );
                        dataMap.put( "gysmcname", gysmcname );
                        dataMap.put( "ysnr", ysnr );
                        dataMap.put( "sl", sl );
                        dataMap.put( "wsdjs", wsdjs );
                        dataList.add( dataMap );
                    }
                    break;
                case "4"://采购需求明细-服务类
                    sql = "select b.fwnr,b.fwyq,b.sl,wm_concat(a.gysmc)as gysmcs,wm_concat( b.wsdj)as wsdjs \n" +
                            "from " + gystb + " a," + gystb + "_dt9 b \n" +
                            "where a.id=b.mainid and a.cglxd=? and a.lc=? group by b.fwnr,b.fwyq,b.sl";
                    rs.executeQuery( sql, cglxd, lc );
                    while (rs.next()) {
                        Map<String, String> dataMap = new HashMap<>();
                        String gysmcs = Util.null2String( rs.getString( "gysmcs" ) );
                        String gysmcname = GenUtil.getId2Gysmcs( gysmcs );
                        String fwnr = Util.null2String( rs.getString( "fwnr" ) );
                        String fwyq = Util.null2String( rs.getString( "fwyq" ) );
                        String wsdjs = Util.null2String( rs.getString( "wsdjs" ) );
                        String sl = Util.null2String( rs.getString( "sl" ) );
                        dataMap.put( "gysmcname", gysmcname );
                        dataMap.put( "fwnr", fwnr );
                        dataMap.put( "fwyq", fwyq );
                        dataMap.put( "wsdjs", wsdjs );
                        dataMap.put( "sl", sl );
                        dataList.add( dataMap );
                    }
                    break;
            }
            datas.put( "lc", lc );
            apidatas.put( "dataList", dataList );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 发起决策明细表1根据采购立项单、轮次获取评标结果会签数据
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getFqjcDt1Data")
    @Produces({MediaType.TEXT_PLAIN})
    public String getFqjcDt1Data(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONArray dataArray = new JSONArray();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            String lc = Util.null2String( request.getParameter( "lc" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String pbjghq = baseBean.getPropValue( "SrmWfTab", "pbjghq" );
            String sql = "select pbfs from " + pbjghq + " where cglxd = ? and lc=?";
            rs.executeQuery( sql, cglxd, lc );
            rs.next();
            String pbfs = Util.null2String( rs.getString( "pbfs" ) );
            if ("0".equals( pbfs )) {
                String sql1 = "select t1.gysmc,t1.zhdf,t1.wstbbj,t1.pm,t1.fktj from " + pbjghq + "  t \n" +
                        "right join " + pbjghq + "_dt1 t1 on t.id=t1.mainid where t.cglxd=? and t.lc=? \n" +
                        "group by t1.gysmc,t1.zhdf,t1.wstbbj,t1.pm,t1.fktj order by t1.pm";
                rs.executeQuery( sql1, cglxd, lc );
                while (rs.next()) {
                    JSONObject data = new JSONObject();
                    String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                    String gysmcname = GenUtil.getId2Gysmc( gysmc );
                    String zhdf = Util.null2String( rs.getString( "zhdf" ) );
                    String wstbbj = Util.null2String( rs.getString( "wstbbj" ) );
                    String pm = Util.null2String( rs.getString( "pm" ) );
                    String fktj = Util.null2String( rs.getString( "fktj" ) );
                    String fktjname = GenUtil.getFktjkxxName( fktj );
                    data.put( "gysmc", gysmc );
                    data.put( "gysmcname", gysmcname );
                    data.put( "zhdf", zhdf );
                    data.put( "wstbbj", wstbbj );
                    data.put( "fktj", fktj );
                    data.put( "fktjname", fktjname );
                    data.put( "pm", pm );
                    dataArray.add( data );
                }
            } else {
                String sql1 = "select t4.gysmc,t4.wstbbj,t4.fktjxs,t4.zfxs,t4.zfxsxs,t4.pm,t4.sftt," +
                        "t4.fktj,t4.sl from " + pbjghq + "  t \n" +
                        "right join " + pbjghq + "_dt4 t4 on t.id=t4.mainid where t.cglxd = ? and t.lc=?";
                rs.executeQuery( sql1, cglxd, lc );
                while (rs.next()) {
                    JSONObject data = new JSONObject();
                    String gysmc = Util.null2String( rs.getString( "gysmc" ) );
                    String gysmcname = GenUtil.getId2Gysmc( gysmc );
                    String wstbbj = Util.null2String( rs.getString( "wstbbj" ) );
                    String fktjxs = Util.null2String( rs.getString( "fktjxs" ) );
                    String zfxs = Util.null2String( rs.getString( "zfxs" ) );
                    String zfxsxs = Util.null2String( rs.getString( "zfxsxs" ) );
                    String pm = Util.null2String( rs.getString( "pm" ) );
                    String sftt = Util.null2String( rs.getString( "sftt" ) );
                    String fktj = Util.null2String( rs.getString( "fktj" ) );
                    String fktjname = GenUtil.getFktjkxxName( fktj );
                    String sl = Util.null2String( rs.getString( "sl" ) );
                    data.put( "gysmc", gysmc );
                    data.put( "gysmcname", gysmcname );
                    data.put( "wstbbj", wstbbj );
                    data.put( "fktjxs", fktjxs );
                    data.put( "zfxs", zfxs );
                    data.put( "zfxsxs", zfxsxs );
                    data.put( "pm", pm );
                    data.put( "sftt", sftt );
                    data.put( "fktj", fktj );
                    data.put( "fktjname", fktjname );
                    data.put( "sl", sl );
                    dataArray.add( data );
                }
            }
            apidatas.put( "pbfs", pbfs );
            apidatas.put( "dataList", dataArray );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据打分表是否全部归档判断评标结果会签按钮是否可用
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getDfbData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getDfbData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            String lc = Util.null2String( request.getParameter( "lc" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String dfb = baseBean.getPropValue( "SrmWfTab", "dfb" );
            String zxpbdf = baseBean.getPropValue( "SrmWfTab", "zxpbdf" );
            String sql = "select count(1) from " + dfb + " t1 \n" +
                    "left join workflow_requestbase t2 on t1.requestid=t2.requestid " +
                    "where t1.cglxd1=? and t1.lc=? and t2.currentnodetype=3";
            rs.executeQuery( sql, cglxd, lc );
            rs.next();
            String dfbcounts = Util.null2String( rs.getString( 1 ) );
            datas.put( "dfbcounts", dfbcounts );
            String sql1 = "select count(column_value) from table(SplitStr(" +
                    "(select pbry from " + zxpbdf + " where cglxd=? and lc=?),','))";
            rs.executeQuery( sql1, cglxd, lc );
            rs.next();
            String zxpfcounts = Util.null2String( rs.getString( 1 ) );
            datas.put( "zxpfcounts", zxpfcounts );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 判断参数日期是否大于当前日期
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/isThanCurDate")
    @Produces({MediaType.TEXT_PLAIN})
    public String isThanCurDate(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            boolean flag = false;
            long ts1 = 0L;
            long ts2 = 0L;
            String date = Util.null2String( request.getParameter( "date" ) );
            if (date.length() > 10) {
                SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
                Date d1 = sdf.parse( date );
                ts1 = d1.getTime();
                Date d2 = sdf.parse( DateUtil.getFullDate() );
                ts2 = d2.getTime();
            } else {
                SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
                Date d1 = sdf.parse( date );
                ts1 = d1.getTime();
                Date d2 = sdf.parse( DateUtil.getCurrentDate() );
                ts2 = d2.getTime();
            }
            if ((ts1 - ts2) >= 0) {
                flag = true;
            }
            apidatas.put( "flag", flag );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单获取资格预审通过的供应商数量
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getZgysDtlCounts")
    @Produces({MediaType.TEXT_PLAIN})
    public String getZgysDtlCounts(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String gyszgys = baseBean.getPropValue( "SrmWfTab", "gyszgys" );
            String sql = "select sum(count(1)) from " + gyszgys + " t " +
                    "left join " + gyszgys + "_dt1 t1\n" +
                    "on t.id=t1.mainid  where cglxd=? and t1.sftg=0 " +
                    "group by gysmc";
            rs.executeQuery( sql, cglxd );
            rs.next();
            String zgyscounts = Util.null2String( rs.getString( 1 ) );
            datas.put( "zgyscounts", zgyscounts );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据在线的人员插入的人员在线表中
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getAddRyzx")
    @Produces({MediaType.TEXT_PLAIN})
    public String getAddRyzx(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            RecordSet rs = new RecordSet();
            rs.writeLog( "in-----------------getAddRyzx" );
            ResourceComInfo ccminfo = new ResourceComInfo();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );//采购立项单
            String ryidsparam = Util.null2String( request.getParameter( "ryids" ) );//人员Ids
            String cgy = Util.null2String( request.getParameter( "cgy" ) );//采购员
            String cgyid = GenUtil.getHrmIdByLoginid( cgy );
            String curdate = DateUtil.getCurrentDate();
            String sfzx = "离线";
            int zxlx = 1;
            String ryids = GenUtil.getCglxd2RyId( cglxd, curdate );
            String[] ryidsList = ryidsparam.split( "," );
            String sql1 = "insert into uf_ryzxb(rymc,ryid,zxrq,sfzx,zxlx,cglxmc,cglxd) values(?,?,?,?,?,?,?)";
            String sql2 = "insert into uf_szkbhq(szan,kban,hqan,cglxd,dqrq,cgy) values (?,?,?,?,?,?)";
            for (String ryid : ryidsList) {
                if (!ryids.contains( ryid )) {
                    String loginid = GenUtil.getHrmIdByLoginid( ryid );
                    String lastname = ccminfo.getLastname( ryid );
                    String cglxmc = GenUtil.getCglx2Name( cglxd );
                    Object[] params = {lastname, loginid, curdate, sfzx, zxlx, cglxmc, cglxd};
                    rs.executeUpdate( sql1, params );
                    rs.writeLog( sql1 );
                }
            }
            rs.executeQuery( "select * from uf_szkbhq where cglxd=? and dqrq=?", cglxd, curdate );
            if (!rs.next()) {
                Object[] params = {0, 0, 1, cglxd, curdate, cgyid};
                rs.executeUpdate( sql2, params );
            }
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单获取设置参数表中的开标方式
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getKbszMainData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getKbszMainData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            String lc = Util.null2String( request.getParameter( "lc" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String kbsz = baseBean.getPropValue( "SrmWfTab", "kbsz" );
            String sql = "select requestid,currentnodetype,kbfs from (\n" +
                    "select t1.requestid,t2.currentnodetype,t1.kbfs from " + kbsz + " t1 \n" +
                    "left join workflow_requestbase t2 on t1.requestid=t2.requestid " +
                    "where t1.cglxd=? and t1.lc=? order by t1.id desc) where rownum<2\n";
            rs.executeQuery( sql, cglxd, lc );
            rs.next();
            String kbfs = Util.null2String( rs.getString( "kbfs" ) );
            String requestid = Util.null2String( rs.getString( "requestid" ) );
            String currentnodetype = Util.null2String( rs.getString( "currentnodetype" ) );
            datas.put( "kbfs", kbfs );
            datas.put( "requestid", requestid );
            datas.put( "currentnodetype", currentnodetype );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据requestid获取发起决策数据
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getFqjcData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getFqjcData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            String lc = Util.null2String( request.getParameter( "lc" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String gyqfqjc = baseBean.getPropValue( "SrmWfTab", "gyqfqjc" );
            String gysjcbg = baseBean.getPropValue( "SrmWfTab", "gysjcbg" );
            String sql2 = "select xbcz from ( select xbcz from " + gysjcbg + " where cglxd=? and lc=? order by id desc) where rownum<2";
            rs.executeQuery( sql2, cglxd, lc );
            boolean flag = rs.next();
            if (flag) {
                String xbcz = Util.null2String( rs.getString( "xbcz" ) );
                datas.put( "xbcz", xbcz );
            } else {
                String sql1 = "select xbcz from ( select xbcz from " + gyqfqjc + " where cglxd=? and lc=? order by id desc) where rownum<2";
                rs.executeQuery( sql1, cglxd, lc );
                rs.next();
                String xbcz = Util.null2String( rs.getString( "xbcz" ) );
                datas.put( "xbcz", xbcz );
            }
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据表名字段名获取workflowid和fieldid
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getFieldid")
    @Produces({MediaType.TEXT_PLAIN})
    public String getFieldid(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            BaseBean baseBean = new BaseBean();
            String formtable = Util.null2String( request.getParameter( "formtable" ) );
            String fieldname = Util.null2String( request.getParameter( "fieldname" ) );
            String table = baseBean.getPropValue( "SrmWfTab", formtable );
            RecordSet rs = new RecordSet();
            String sql = "select concat('field',t1.id)as fieldid from workflow_billfield t1 \n" +
                    "left join workflow_base t2 on t1.billid=t2.formid \n" +
                    "where t1.fieldname=? and concat('formtable_main_',abs(t2.formid)) =?";
            rs.executeQuery( sql, fieldname, table );
            rs.next();
            String fieldid = Util.null2String( rs.getString( "fieldid" ) );
            apidatas.put( "fieldid", fieldid );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据表名字段名获取workflowid
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getWorkflowid")
    @Produces({MediaType.TEXT_PLAIN})
    public String getWorkflowid(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            BaseBean baseBean = new BaseBean();
            String formtable = Util.null2String( request.getParameter( "formtable" ) );
            String table = baseBean.getPropValue( "SrmWfTab", formtable );
            RecordSet rs = new RecordSet();
            String sql = "select t2.id as workflowid from workflow_billfield t1 left join workflow_base t2 on t1.billid=t2.formid \n" +
                    "where concat('formtable_main_',abs(t2.formid)) =? group by t2.id";
            rs.executeQuery( sql, table );
            rs.next();
            String workflowid = Util.null2String( rs.getString( "workflowid" ) );
            apidatas.put( "workflowid", workflowid );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据表名字段名获取workflowid
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getIsExistWfid")
    @Produces({MediaType.TEXT_PLAIN})
    public String getIsExistWfid(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            String workflowid = Util.null2String( request.getParameter( "workflowid" ) );
            RecordSet rs = new RecordSet();
            String sql = "select id from uf_lckz where xzlc=?";
            boolean flag = false;
            rs.executeQuery( sql, workflowid );
            if (rs.next()) {
                flag = true;
            }
            apidatas.put( "api_status", flag );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 获取当前登陆者信息返回前台
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getUserInfo")
    @Produces({MediaType.TEXT_PLAIN})
    public String getUserInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            User user = HrmUserVarify.getUser( request, response );
            String loginid = user.getLoginid();
            String logintype = user.getLogintype();
            String username = user.getUsername();
            datas.put( "loginid", loginid );
            datas.put( "logintype", logintype );
            datas.put( "username", username );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 判断竞价是否开始
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getBidIsBegin")
    @Produces({MediaType.TEXT_PLAIN})
    public String getBidIsBegin(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            RecordSet rs = new RecordSet();
            boolean flag = true;
            String sql = "select ksjj,jjkssj from uf_biddinginfo where cglxd=?";
            rs.executeQuery( sql, cglxd );
            rs.next();
            int ksjj = Util.getIntValue( rs.getString( "ksjj" ) );
            String jjkssj = Util.null2String( rs.getString( "jjkssj" ) );
            if (ksjj > 0 && "".equals( jjkssj )) {
                flag = false;
            } else if (ksjj <= 0 && !"".equals( jjkssj )) {
                flag = false;
            }
            apidatas.put( "flag", flag );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 判断招采是否转竞价
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getCglx2Jjlx")
    @Produces({MediaType.TEXT_PLAIN})
    public String getCglx2Jjlx(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            JSONObject datas = new JSONObject();
            String jjcglx = baseBean.getPropValue( "SrmWfTab", "jjcglx" );
            String sql = "select m.requestid,concat(m.jjkssj,':00')as begintime,n.currentnodetype from " + jjcglx + " m \n" +
                    "left join workflow_requestbase n on m.requestid=n.requestid where m.gllx=?";
            rs.executeQuery( sql, cglxd );
            if (rs.next()) {
                String requestid = Util.null2String( rs.getString( "requestid" ) );
                String begintime = Util.null2String( rs.getString( "begintime" ) );
                String currentnodetype = Util.null2String( rs.getString( "currentnodetype" ) );
                datas.put( "requestid", requestid );
                datas.put( "currentnodetype", currentnodetype );
                datas.put( "begintime", begintime );
                datas.put( "flag", true );
            } else {
                datas.put( "flag", false );
            }
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 获取供应商邀请回执个数，查看邀请回执各个数，回执完成个数
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getGysyqCounts")
    @Produces({MediaType.TEXT_PLAIN})
    public String getGysyqCounts(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            String jjlxd = Util.null2String( request.getParameter( "jjlxd" ) );
            RecordSet rs = new RecordSet();
            BaseBean baseBean = new BaseBean();
            String gysyqhzjj = baseBean.getPropValue( "SrmWfTab", "gysyqhzjj" );
            int totalCounts = 0;//邀请回执总流程数
            int viewCounts = 0;//流程查看数
            int compCounts = 0;//流程归档数
            String sql1 = "select count(iscomplete) AS iscomplete from (\n" +
                    "select t1.iscomplete from workflow_currentoperator t1 \n" +
                    "left join " + gysyqhzjj + " t2 on t1.requestid=t2.requestid where t2.cglxd=? and t1.iscomplete=1\n" +
                    "group by t1.requestid,t1.iscomplete,t2.gysmc) ";
            rs.executeQuery( sql1, jjlxd );
            if (rs.next()) {
                compCounts = Util.getIntValue( rs.getString( "iscomplete" ) );
            }

            String sql2 = "select count(viewtype)AS viewtype from (\n" +
                    "select t1.viewtype from workflow_currentoperator t1 \n" +
                    "left join " + gysyqhzjj + " t2 on t1.requestid=t2.requestid where t2.cglxd=? and t1.viewtype='-2'\n" +
                    "group by t1.requestid,t1.viewtype,t2.gysmc ) ";
            rs.executeQuery( sql2, jjlxd );
            if (rs.next()) {
                viewCounts = Util.getIntValue( rs.getString( "viewtype" ) );
            }
            String sql3 = "select count(requestid)AS total from (\n" +
                    "select t1.requestid from workflow_currentoperator t1 \n" +
                    "left join " + gysyqhzjj + " t2 on t1.requestid=t2.requestid where t2.cglxd=? \n" +
                    "group by t1.requestid,t2.gysmc ) ";
            rs.executeQuery( sql3, jjlxd );
            if (rs.next()) {
                totalCounts = Util.getIntValue( rs.getString( "total" ) );
            }

            datas.put( "totalCounts", totalCounts );
            datas.put( "viewCounts", viewCounts );
            datas.put( "compCounts", compCounts );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据公布结果获取提交报价明细的供应商
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getGysPirceDtl")
    @Produces({MediaType.TEXT_PLAIN})
    public String getGysPirceDtl(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            String jjlxd = Util.null2String( request.getParameter( "jjlxd" ) );
            BaseBean baseBean = new BaseBean();
            String tjbjmxjj = baseBean.getPropValue( "SrmWfTab", "tjbjmxjj" );
            RecordSet rs = new RecordSet();
            String sql = "select count(requestid)as counts from " + tjbjmxjj + " where cglxd =?";
            rs.executeQuery( sql, jjlxd );
            rs.next();
            int totalCounts = Util.getIntValue( rs.getString( "counts" ) );//提交报价明细供应商总数

            String sql1 = "select jjlc,lc from " + tjbjmxjj + " where cglxd =? group by jjlc,lc";
            rs.executeQuery( sql1, jjlxd );
            rs.next();
            int jjlc = Util.getIntValue( rs.getString( "jjlc" ) );//竞价轮次
            int lc = Util.getIntValue( rs.getString( "lc" ) );//轮次
            String sql2 = "select count(m.requestid)as counts from " + tjbjmxjj + " m left join workflow_requestbase n " +
                    "on m.requestid=n.requestid where m.cglxd=? and n.currentnodetype>0";
            rs.executeQuery( sql2, jjlxd );
            rs.next();
            int compCounts = Util.getIntValue( rs.getString( "counts" ) );//已提交报价明细供应商数
            datas.put( "totalCounts", totalCounts );
            datas.put( "compCounts", compCounts );
            datas.put( "jjlc", jjlc );
            datas.put( "lc", lc );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 根据采购立项单获取公布结果
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2021/3/1
     */
    @GET
    @Path("/getPublishResult")
    @Produces({MediaType.TEXT_PLAIN})
    public String getPublishResult(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            JSONObject datas = new JSONObject();
            RecordSet rs = new RecordSet();
            String cglxd = Util.null2String( request.getParameter( "cglxd" ) );
            String sql = "select id from uf_gbjg where cglxd=?";
            rs.executeQuery( sql, cglxd );
            boolean falg = rs.next();
            datas.put( "falg", falg );
            apidatas.put( "datas", datas );
            apidatas.put( "api_status", true );
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put( "api_status", false );
            apidatas.put( "api_errormsg", "catch exception : " + e.getMessage() );
        }
        return JSONObject.toJSONString( apidatas );
    }
}